<?php

namespace app\admin\controller;

use think\facade\App;

class Config extends Base {

    /**
     * @desc 配置管理
     */
    public function index() {
        $params['keyword'] = input('keyword');
        $params['group']   = input('group');

        $logic = App::model('Config', 'logic');
        $data = $logic->index($params);

        $this->assign($data);
        return view();
    }

    /**
     * @desc 添加配置
     */
    public function add() {
        $params['action'] = input('action');

        $this->assign([
            'params' => $params
        ]);
        return view();
    }

    /**
     * @desc 编辑配置
     */
    public function edit() {
        $params['action'] = input('action');
        $params['id']     = input('id');

        $logic = App::model('Config', 'logic');
        $data = $logic->edit($params);

        $this->assign($data);
        return view();
    }

    /**
     * @desc 配置管理 (添加、编辑)
     */
    public function operateAjax() {
        $params['action'] = input('action');
        $params['id']     = input('id', 0);

        $params['title']  = input('title');
        $params['key']    = input('key');
        $params['value']  = input('value');
        $params['group']  = input('group');

        $logic = model('Config', 'logic');
        $data = [];
        try {
            $data = $logic->operateAjax($params);
        } catch (\Exception $e) {
            $logic->errorCode = EC_FAILURE;
            $logic->message = $e->getMessage();
        }
        return send_response($data, $logic->errorCode, $logic->message);
    }

    /**
     * @desc 删除配置
     */
    public function del() {
        return view();
    }
}
